this.BX=this.BX||{};this.BX.Landing=this.BX.Landing||{};this.BX.Landing.UI=this.BX.Landing.UI||{};(function(e,t,i){"use strict";let n=e=>e,s;class a extends t.BaseField{constructor(e){super(e);BX.Landing.UI.Field.BaseField.apply(this,arguments);this.options=e.options||{};i.Dom.remove(this.input);this.onValueChangeHandler=e.onValueChange?e.onValueChange:function(){};this.content=i.Type.isPlainObject(this.content)?this.content:{};this.content=BX.Landing.Utils.clone(this.content);this.content.text=BX.Landing.Utils.trim(this.content.text);this.content.href=BX.Landing.Utils.trim(BX.Landing.Utils.escapeText(this.content.href));this.content.target=BX.Landing.Utils.trim(BX.Landing.Utils.escapeText(this.content.target));this.skipContent=e.skipContent;this.detailPageMode=e.detailPageMode===true;if(!this.containsImage()&&!this.containsHtml()){if(i.Type.isStringFilled(this.content.text)){this.content.text=this.content.text.replace("&nbsp;"," ")}this.content.text=BX.Landing.Utils.escapeText(this.content.text)}this.input=new BX.Landing.UI.Field.Text({placeholder:BX.Landing.Loc.getMessage("FIELD_LINK_TEXT_LABEL"),selector:this.selector,content:i.Text.decode(this.content.text),textOnly:true,onValueChange:function(){this.onValueChangeHandler(this);if(this.hrefInput.getValue()===this.hrefInput.typeHrefs.page+"#landing0"){const e=this.input.getValue();const t=this.hrefInput.input.firstElementChild;if(t){const n=t.querySelector(".landing-ui-field-url-placeholder-text");n.innerText=i.Text.decode(e.replace(/&nbsp;/g," "))}}const e=new i.Event.BaseEvent({data:{value:this.getValue()},compatData:[this.getValue()]});this.emit("change",e)}.bind(this)});if(this.skipContent){this.input.layout.hidden=true;this.header.hidden=true}this.hrefInput=new BX.Landing.UI.Field.LinkUrl({title:BX.Landing.Loc.getMessage("FIELD_LINK_HREF_LABEL_2"),placeholder:"",selector:this.selector,content:this.content.href,contentRoot:this.contentRoot,onInput:this.onHrefInput.bind(this),textOnly:true,options:this.options,disallowType:e.disallowType,disableBlocks:e.disableBlocks,allowedTypes:e.allowedTypes,detailPageMode:e.detailPageMode===true,sourceField:e.sourceField,onValueChange:function(){this.onValueChangeHandler(this);const e=new BX.Event.BaseEvent({data:{value:this.getValue()},compatData:[this.getValue()]});this.emit("change",e)}.bind(this),onNewPage:function(){const e=this.input.getValue();const t=this.hrefInput.input.firstElementChild;if(t){const i=t.querySelector(".landing-ui-field-url-placeholder-text");i.innerHTML=e.replace(/&nbsp;/g," ")}}.bind(this)});this.targetInput=new BX.Landing.UI.Field.DropdownInline({title:BX.Landing.Loc.getMessage("FIELD_LINK_TARGET_LABEL"),selector:this.selector,className:"landing-ui-field-dropdown-inline",content:this.content.target,contentRoot:this.contentRoot,items:{_self:BX.Landing.Loc.getMessage("FIELD_LINK_TARGET_SELF"),_blank:BX.Landing.Loc.getMessage("FIELD_LINK_TARGET_BLANK"),_popup:BX.Landing.Loc.getMessage("FIELD_LINK_TARGET_POPUP")},onValueChange:function(){this.onValueChangeHandler(this);const e=new BX.Event.BaseEvent({data:{value:this.getValue()},compatData:[this.getValue()]});this.emit("change",e)}.bind(this)});this.stateNode=i.Tag.render(s||(s=n`
			<div class="landing-ui-field-url-state-box"></div>
		`));this.mediaLayout=i.Dom.create("div",{props:{className:"landing-ui-field-link-media-layout"}});if(this.containsImage()||this.containsHtml()){this.input.layout.hidden=true;this.header.hidden=true;this.hrefInput.header.innerHTML=this.header.innerHTML}this.wrapper=BX.Landing.UI.Field.Link.createWrapper();this.left=BX.Landing.UI.Field.Link.createLeft();this.center=BX.Landing.UI.Field.Link.createCenter();this.right=BX.Landing.UI.Field.Link.createRight();i.Dom.append(this.input.layout,this.left);i.Dom.append(this.hrefInput.layout,this.center);this.targetInput=this.createTargetInput(this.hrefInput.getRightData());this.right.innerHTML="";if(this.targetInput.hasOwnProperty("layout")){i.Dom.append(this.targetInput.layout,this.right)}else{i.Dom.append(this.targetInput,this.right)}this.showElement(this.right);const t=this.hrefInput.getSelectedHrefType();if(t===this.hrefInput.typeHrefs.start){this.hideElement(this.right)}const a=this.hrefInput.getTypeData(t);this.checkVisibleMediaPanel(t,this.targetInput.getValue());this.targetInput.subscribe("onChange",(()=>{this.checkVisibleMediaPanel(t,this.targetInput.getValue())}));if(a.hasOwnProperty("hideInput")){const e=this.hrefInput.gridCenterCell.querySelector(".landing-ui-field-input");e.hidden=!!a.hideInput}const r=this.center.querySelector(".landing-ui-field-link-url-grid-center");i.Dom.append(this.stateNode,r);i.Dom.addClass(r,"--only-manual-entry");if(a.hasOwnProperty("button")){if(!r.querySelector(".landing-ui-button-grid-center-cell")){const e=this.hrefInput.createCenterCellButton(a.button);i.Dom.append(e.layout,r);i.Dom.removeClass(r,"--only-manual-entry")}}this.hrefInput.subscribe("deleteAction",(()=>{if(this.hrefInput.getSelectedHrefType()===this.hrefInput.typeHrefs.start){this.hideElement(this.right)}}));this.hrefInput.subscribe("selectAction",(e=>{const t=this.hrefInput.getSelectedHrefType();const n=this.hrefInput.getTypeData(t);this.prepareGridCenter(t);const s=this.hrefInput.gridCenterCell.querySelector(".landing-ui-field-input");s.hidden=!!n.hideInput;this.targetInput=this.createTargetInput(e.data.right);if(!i.Type.isUndefined(this.selectedTargetValueByUser)){this.targetInput.setValue(this.selectedTargetValueByUser)}this.targetInput.subscribe("onItemClick",(()=>{this.selectedTargetValueByUser=this.targetInput.getValue()}));this.right.innerHTML="";if(this.targetInput.hasOwnProperty("layout")){i.Dom.append(this.targetInput.layout,this.right)}else{i.Dom.append(this.targetInput,this.right)}this.showElement(this.right);this.checkVisibleMediaPanel(t,this.targetInput.getValue());this.targetInput.subscribe("onChange",(()=>{this.checkVisibleMediaPanel(t,this.targetInput.getValue())}));this.disableMedia();this.adjustTarget()}));this.hrefInput.subscribe("buildCenter",(e=>{const t=this.hrefInput.gridCenterCell.querySelector(".landing-ui-button-grid-center-cell");const n=this.center.querySelector(".landing-ui-field-link-url-grid-center");if(t){t.remove()}i.Dom.append(this.stateNode,n);if(e.data.button){i.Dom.append(e.data.button.layout,n);i.Dom.removeClass(n,"--only-manual-entry")}else{i.Dom.addClass(n,"--only-manual-entry")}}));i.Dom.append(this.left,this.wrapper);i.Dom.append(this.center,this.wrapper);i.Dom.append(this.right,this.wrapper);i.Dom.append(this.wrapper,this.layout);i.Dom.append(this.mediaLayout,this.layout);i.Dom.addClass(this.layout,"landing-ui-field-link");if(this.hrefInput.getSelectedHrefType()===""){if(this.content.target==="_popup"){this.adjustVideo()}}this.adjustEditLink();this.adjustTarget();this.targetInput.subscribe("onItemClick",(()=>{this.selectedTargetValueByUser=this.targetInput.getValue()}));this.hrefInput.subscribe("readyToSave",(e=>{if(e.data.readyToSave){this.readyToSave=true;this.emit("onChangeReadyToSave")}else{this.readyToSave=false;this.emit("onChangeReadyToSave")}}))}static createWrapper(){return i.Dom.create("div",{props:{className:"landing-ui-field-link-wrapper"}})}static createCenter(){return i.Dom.create("div",{props:{className:"landing-ui-field-link-center"}})}static createLeft(){return i.Dom.create("div",{props:{className:"landing-ui-field-link-left"}})}static createRight(){return i.Dom.create("div",{props:{className:"landing-ui-field-link-right"}})}hideElement(e){e.hidden=true}showElement(e){e.hidden=false}createTargetInput(e){const t=e.title||"";const i=e.items||{};return new BX.Landing.UI.Field.DropdownInline({title:t,selector:this.selector,className:"landing-ui-field-dropdown-inline",content:this.content.target,contentRoot:this.contentRoot,items:i,onValueChange:function(){this.onValueChangeHandler(this);const e=new BX.Event.BaseEvent({data:{value:this.getValue()},compatData:[this.getValue()]});this.emit("change",e)}.bind(this)})}adjustEditLink(){const e=this.hrefInput.getPlaceholderType();const t=BX.Landing.Env.getInstance().getType();if(e==="PAGE"&&t!=="KNOWLEDGE"&&t!=="GROUP"){const e=this.hrefInput.getValue();if(i.Type.isString(e)&&e.length>0){this.hrefInput.getPageData(e).then(function(e){const t=BX.Landing.Main.getInstance().options.params.sef_url.landing_view;const n=t.replace("#site_show#",e.siteId).replace("#landing_edit#",e.id);[].slice.call(this.layout.querySelectorAll(".landing-ui-field-edit-link")).forEach(BX.remove);this.editLink=this.createEditLink(BX.Landing.Loc.getMessage("LANDING_LINK_FILED__EDIT_PAGE_LINK_LABEL"),n);i.Dom.append(this.editLink,this.layout)}.bind(this))}}}createEditLink(e,t){return i.Dom.create("div",{props:{className:"landing-ui-field-edit-link"},children:[i.Dom.create("a",{attrs:{href:t,target:a.TARGET_BLANK,title:BX.Landing.Loc.getMessage("LANDING_LINK_FILED__EDIT_LINK_TITLE")},text:e})]})}isChanged(){const e=JSON.stringify(this.content)!==JSON.stringify(this.getValue());if(e){this.prepareHrefInput();this.prepareTargetInput()}return e}containsImage(){return!!i.Dom.create("div",{html:this.content.text}).querySelector("img")}containsHtml(){const e=BX.Landing.Utils.htmlToElement(this.content.text);return!!e&&!e.matches("br")}getValue(){const e={text:BX.Landing.Utils.decodeDataValue(BX.Landing.Utils.trim(this.input.getValue().replace(/&nbsp;/g," "))),href:BX.Landing.Utils.trim(this.hrefInput.getValue()),target:this.prepareTarget(BX.Landing.Utils.trim(this.targetInput.getValue()))};if(this.isAvailableMedia()&&this.mediaService){e.attrs={"data-url":BX.Landing.Utils.trim(this.mediaService.getEmbedURL())}}if(this.hrefInput.getDynamic()){if(!i.Type.isPlainObject(e.attrs)){e.attrs={}}if(this.hrefInput.input.firstElementChild){e.attrs["data-url"]=this.hrefInput.input.firstElementChild.getAttribute("data-url")}e.attrs["data-dynamic"]=this.hrefInput.getDynamic()}if(this.skipContent){delete e["text"]}if(e.href.startsWith("selectActions:")){e.href="#"}return e}setValue(e){if(i.Type.isPlainObject(e)){this.input.setValue(BX.Landing.Utils.escapeText(e.text));this.hrefInput.setValue(e.href);this.targetInput.setValue(BX.Landing.Utils.escapeText(e.target))}this.adjustEditLink();this.adjustTarget()}adjustTarget(){if(!this.isAvailableMedia()){const e=BX.Landing.Env.getInstance().getType();const t=this.getValue();this.targetInput.enable();if(e==="KNOWLEDGE"||e==="GROUP"){this.targetInput.disable();const e=this.hrefInput.getSelectedHrefType();if(e==="page:"||e==="block:"||e==="form:"||e==="user:"||/^#(\w+)([0-9])$/.test(t.href)){this.targetInput.setValue(a.TARGET_SELF)}else{this.targetInput.setValue(a.TARGET_BLANK)}}else{if(t.href.startsWith("#crmFormPopup")){this.targetInput.disable()}if(t.href.startsWith("#crmPhone")){this.targetInput.disable()}}}}enableMedia(){this.readyToSave=true;if(!this.mediaService.isDataLoaded){this.readyToSave=false;BX.addCustomEvent(this.mediaService,"onDataLoaded",(()=>{this.readyToSave=true;this.emit("onChangeReadyToSave")}))}this.emit("onChangeReadyToSave");this.showMediaPreview()}disableMedia(){if(!this.readyToSave){this.readyToSave=true;this.emit("onChangeReadyToSave")}this.hideMediaPreview();this.hideMediaSettings()}showMediaSettings(){if(this.isAvailableMedia()){this.hideMediaSettings();this.mediaSettings=this.mediaService.getSettingsForm();if(this.mediaSettings){i.Dom.append(this.mediaSettings.layout,this.mediaLayout)}}}hideMediaSettings(){if(this.mediaSettings){i.Dom.remove(this.mediaSettings.layout)}}isAvailableMedia(){const e=new BX.Landing.MediaService.Factory;return!!e.getRelevantClass(this.hrefInput.getValue())}showMediaPreview(){const e=new BX.Loader({target:this.mediaLayout,mode:"inline",offset:{top:"calc(50% - 55px)",left:"calc(50% - 55px)"}});this.video=e.layout;e.show();return this.mediaService.getURLPreviewElement().then(function(t){i.Dom.remove(this.video);e.hide();this.video=t;i.Dom.append(this.video,this.mediaLayout);this.targetValueBeforeAutochange=this.targetInput.getValue();if(i.Type.isUndefined(this.selectedTargetValueByUser)){this.targetInput.setValue("_popup")}this.showMediaSettings()}.bind(this),function(){this.hideMediaSettings();i.Dom.remove(this.video)}.bind(this))}hideMediaPreview(){if(i.Type.isUndefined(this.selectedTargetValueByUser)){this.targetInput.setValue(this.targetValueBeforeAutochange)}if(this.video){i.Dom.remove(this.video)}}adjustVideo(){const e=BX.Landing.Env.getInstance().getType();if(e!=="KNOWLEDGE"&&e!=="GROUP"){const e="attrs"in this.content&&"data-url"in this.content.attrs?this.content.attrs["data-url"]:"";const t=new BX.Landing.MediaService.Factory;this.mediaService=t.create(this.hrefInput.getValue(),BX.Landing.Utils.getQueryParams(e));if(this.mediaService){this.disableMedia();if(this.isAvailableMedia()){this.enableMedia()}}else{this.disableMedia()}}}onHrefInput(){const e=this.hrefInput.getSelectedHrefType();const t=this.hrefInput.getTypeData(e);if(t.hasOwnProperty("validate"));if(e===""){this.adjustVideo()}this.adjustEditLink();this.adjustTarget()}checkVisibleMediaPanel(e,t){if(e===""&&t==="_popup"){this.showMediaPanel()}else{this.hideMediaPanel()}}showMediaPanel(){this.mediaLayout.hidden=false}hideMediaPanel(){this.mediaLayout.hidden=true}prepareHrefInput(){if(this.hrefInput.getValue()===""||this.hrefInput.getValue()==="#"){this.hrefInput.setHrefTypeSwitcherValue(this.hrefInput.typeHrefs.start)}}prepareTargetInput(){if(this.hrefInput.getSelectedHrefType()===this.hrefInput.typeHrefs.user){this.targetInput.setValue(a.TARGET_BLANK)}if(this.hrefInput.getSelectedHrefType()===this.hrefInput.typeHrefs.start){this.targetInput.setValue(a.TARGET_SELF)}}prepareGridCenter(e){const t=[this.hrefInput.typeHrefs.block,this.hrefInput.typeHrefs.page,this.hrefInput.typeHrefs.form,this.hrefInput.typeHrefs.product,this.hrefInput.typeHrefs.file,this.hrefInput.typeHrefs.user];i.Dom.removeClass(this.hrefInput.gridCenterCell,"--not-empty");if(t.includes(e)){i.Dom.addClass(this.hrefInput.gridCenterCell,"--not-manual-input")}else{i.Dom.removeClass(this.hrefInput.gridCenterCell,"--not-manual-input")}}prepareTarget(e){if(this.hrefInput.getSelectedHrefType()===this.hrefInput.typeHrefs.user){e=a.TARGET_BLANK}return e}}a.TARGET_SELF="_self";a.TARGET_BLANK="_blank";e.Link=a})(this.BX.Landing.UI.Field=this.BX.Landing.UI.Field||{},BX.Landing.UI.Field,BX);
//# sourceMappingURL=link.bundle.map.js